🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

parallax-controller

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parallax-controller

[![npm version](https://badge.fury.io/js/parallax-controller.svg)](https://badge.fury.io/js/parallax-controller) [![codecov](https://codecov.io/gh/jscottsmith/parallax-controller/branch/master/graph/badge.svg)](https://codecov.io/gh/jscottsmith/parallax-c

0.1.36
Source
npm
Version published
Weekly downloads
33K
-25.11%
Maintainers
1
Weekly downloads
 
Created
Source

🕹 Parallax Controller

npm version codecov

Core classes and controller for creating parallax scrolling effects.

This package was created for react-scroll-parallax, but can be used as a standalone lib.

Usage

Create the parallax controller first:

const controller = ParallaxController.init();

Then create an element with animation effects as props:

controller.createElement({
  elOuter: document.getElementById('outer'),
  elInner: document.getElementById('inner'),
  props: {
    translateY: [-100, 100],
    opacity: [0.4, 1],
  },
});
<div id="outer">
  <div id="inner">
    <!-- children  -->
  </div>
</div>

Optimizations to Reduce Jank

A number of techniques are used to keep scrolling optimized:

  • Uses a single passive scroll listener to control all animated elements on the page.
  • A minimal amount of work is done on the scroll event to prevent jank with no calls to methods that cause layout shifts.
  • Calculations that cause layout, reflow (getBoundingClientRect()) are cached and only updated when layout may change.
  • The requestAnimationFrame is used to apply all scroll effects.
  • Only GPU supported CSS effects transform and opacity are allowed.
  • CSS will-change is added to an element based on animation effects to prevent paints.

If you have ideas to further optimize scrolling please PR or post an issue.

⚠️ Scroll Effects May Still Cause Jank and Bad User Experiences!

It's up to you to make sure you use this package appropriately. Here's some suggestions for usage while maintaining good UX:

  • Keep effects simple -- less is more. Oftentimes the less extreme animations on the page the better the scrolling will be.
  • Minimize the number of scroll effects on elements that are in view at the same time.
  • When using images keep them small and optimized. Hi-resolution images will hurt scroll performance.
  • Disable most (or all) scroll effects on mobile. Mobile devices optimize for best battery life and animation performance will often be degraded.

FAQs

Package last updated on 05 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts